/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package javaapplication1;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 *
 * @author abosancic
 */
public class SQLiteParser {
    
    private String sqliteDLL;
    private Map<String, String> columns = new HashMap<>();
    private String tableName;
    private String primaryKeyName;

    public SQLiteParser(String sqliteDLL) {
        this.sqliteDLL = sqliteDLL;
        parse(sqliteDLL);
    }

    private void parse(String sqliteDLL) {
       
        String [] dll = sqliteDLL.split("\n");
        
            for (int j = 0; j < dll.length; j++) {
                
                dll[j] = dll[j].replaceAll(",", "").replaceAll("\n", "");
                
                if(dll[j].startsWith("CREATE TABLE"))
                {
                    this.tableName = dll[j].replace("CREATE TABLE", "").trim().replaceAll("\"", "").replace("(", "").trim();
                }
                else if(dll[j].startsWith("PRIMARY KEY"))
                {
                    this.primaryKeyName = dll[j].replace("PRIMARY KEY", "").trim().replace("(", "").replace(")", "").replaceAll("\"", "").trim();
                }
                else if(dll[j].startsWith("\""))
                {
                    String tmp [] = dll[j].replaceAll("  ", " ").replaceAll("\"", "").split(" ");
                    columns.put(tmp[0], tmp[1]);
                }
                //System.out.println(dll[j]);
            }
            
    }

    @Override
    public String toString() {
        return "SQLiteParser{" + "sqliteDLL=" + sqliteDLL + ",\n\n columns=" + columns + ",\n\n tableName=" + tableName + ", primaryKeyName=" + primaryKeyName + '}';
    }
    
    
    
}
